package admin

import (
	"github.com/astaxie/beego"
	"lphoto/models"
)

type BaseController struct {
	beego.Controller
	LoginUser models.UserInfo
}


func (c * BaseController) responseSuccess(info string, data interface{})  {
	c.responseJson(1, info, data)
}
func (c * BaseController) responseFail(info string, data interface{})  {
	c.responseJson(0, info, data)
}
func (c * BaseController) responseJson(code int, info string, data interface{})  {

	result := map[string]interface{}{"code": code, "info": info, "data": data}
	c.Data["json"] = result
	c.ServeJSON()
	c.StopRun()
}

// xsrf处理
func (c *BaseController) Prepare()  {
	c.Data["xsrf_token"] = c.XSRFToken()
	c.Data["userInfo"] = c.GetSession("userInfo")
	if c.GetSession("userInfo") != nil {
		user,_ := c.GetSession("userInfo").(*models.UserInfo)
		c.LoginUser = *user
	}
	c.Data["oss_url"] = beego.AppConfig.String("oss_url")
}
